package com.basics.common.utils.security;


import com.basics.common.exception.CustomException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityUtils {
    public SecurityUtils() {
    }

    public static String getUserId() {
        try {
            return getLoginUser().getUserId();
        } catch (Exception var1) {
            throw new CustomException("获取用户账户异常", 401);
        }
    }

    public static String getUsername() {
        try {
            return getLoginUser().getUsername();
        } catch (Exception var1) {
            throw new CustomException("获取用户账户异常", 401);
        }
    }

    public static LoginUser getLoginUser() {
        try {
            return (LoginUser)getAuthentication().getPrincipal();
        } catch (Exception var1) {
            throw new CustomException("获取用户信息异常", 401);
        }
    }

    public static Authentication getAuthentication() {
        return SecurityContextHolder.getContext().getAuthentication();
    }
}
